using AiQiuQuan.Sport.Model.Models;
using AiQiuQuan.Sport.Core;
using AiQiuQuan.Sport.WebApi.Services;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;

namespace AiQiuQuan.Sport.WebApi.Controllers
{
    /// <summary>
    /// 场馆管理
    /// </summary>
    public class VenueController : ApiController
    {
        private readonly IVenueService _venueService;

        /// <summary>
        /// cotr
        /// </summary>
        public VenueController(
            IVenueService venueService)
        {
            _venueService = venueService;
        }

        /// <summary>
        /// 查询
        /// </summary>
        [HttpGet("get")]
        public async Task<UnaryResult<VenueInfoDto>> GetAsync([Required] Guid id)
        {
            var result = await _venueService.GetAsync(id);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        [HttpPost("pagelist")]
        public async Task<UnaryResult<PageResult<VenueInfoDto>>> PageListAsync(VenuePageRequestDto request)
        {
            var result = await _venueService.PageListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 教练场馆分页
        /// </summary>
        [HttpPost("pagelist_coacher_venue")]
        [AllowAnonymous]
        public async Task<UnaryResult<PageResult<VenueInfoDto>>> PageListCoacherAsync(VenuePageRequestDto request)
        {
            var result = await _venueService.PageListCoacherAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 场馆教练更新
        /// </summary>
        [HttpPost("update_coacher")]
        public async Task<UnaryResult> UpdateVenueCoacherAsync(VenueCoacherUpdateDto request)
        {
            var result = await _venueService.UpdateVenueCoacherAsync(request);
            return result;
        }

        /// <summary>
        /// 场地列表
        /// </summary>
        /// <param name="venueId">场馆ID</param>
        [HttpGet("list_site")]
        public async Task<UnaryResult<List<SiteInfoDto>>> GetVenueSiteListAsync([Required] Guid venueId)
        {
            var list = await _venueService.GetVenueSiteListAsync(venueId);
            return UnaryResult.Succeed(list);
        }

        /// <summary>
        /// 场地状态更新
        /// </summary>
        [HttpPost("update_site_state")]
        public async Task<UnaryResult> UpdateSiteStateAsync(VenueSiteStateUpdateDto request)
        {
            var result = await _venueService.UpdateSiteStateAsync(request);
            return result;
        }

        /// <summary>
        /// 获取场地价格特殊规则列表
        /// </summary>
        /// <param name="siteId">地址ID</param>
        [HttpGet("list_site_special_rule")]
        public async Task<UnaryResult<List<SitePriceSpecialRuleDto>>> GetPriceSpecialRuleListAsync([Required] Guid siteId)
        {
            var result = await _venueService.GetPriceSpecialRuleListAsync(siteId);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 场地价格特殊规则增加
        /// </summary>
        [HttpPost("add_site_special_rule")]
        public async Task<UnaryResult> AddSiteSpecialRuleAsync(SitePriceSpecialRuleAddDto request)
        {
            var result = await _venueService.AddSiteSpecialRuleAsync(request);
            return result;
        }

        /// <summary>
        /// 场地价格特殊规则更新
        /// </summary>
        [HttpPost("update_site_special_rule")]
        public async Task<UnaryResult> UpdateSiteSpecialRuleAsync(SitePriceSpecialRuleUpdateDto request)
        {
            var result = await _venueService.UpdateSiteSpecialRuleAsync(request);
            return result;
        }

        /// <summary>
        /// 场地价格特殊规则状态更新
        /// </summary>
        [HttpPost("update_site_special_rule_state")]
        public async Task<UnaryResult> UpdateSiteSpecialRuleStateAsync(SitePriceSpecialRuleStateUpdateDto request)
        {
            var result = await _venueService.UpdateSiteSpecialRuleStateAsync(request);
            return result;
        }

        /// <summary>
        /// 场地价格特殊规则删除
        /// </summary>
        /// <param name="siteSpecialRuleID">场地价格特殊规则ID</param>
        [HttpGet("delete_site_special_rule")]
        public async Task<UnaryResult> DeleteSiteSpecialRuleAsync([Required] Guid siteSpecialRuleID)
        {
            var result = await _venueService.DeleteSiteSpecialRuleAsync(siteSpecialRuleID);
            return UnaryResult.Succeed();
        }
    }
}
